﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Warhammer40K_Simulator.view
{
    /// <summary>
    /// Interaction logic for optionlist.xaml
    /// </summary>
    public partial class optionlist : UserControl
    {

        public static readonly DependencyProperty titleproperty = DependencyProperty.Register("title"
        , typeof(String)
        , typeof(view.optionlist)
        , new PropertyMetadata(title_PropertyChanged));

        public String Title
        {
            get { return (String)GetValue(titleproperty); }
            set { SetValue(titleproperty, value); }
        }

        protected static void title_PropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
        }

        public optionlist()
        {
            InitializeComponent();
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(optionlist_DataContextChanged);
        }

        void optionlist_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            stackpanel_elements.Children.Clear();
            ObservableCollection<model.optiongroup> optiongroups = e.NewValue as ObservableCollection<model.optiongroup>;

            if (optiongroups != null && optiongroups.Count > 0)
            {
                if (Title != null && Title != "")
                {
                    textblock_label.Visibility = Visibility.Visible;
                }
                stackpanel_elements.Visibility = Visibility.Visible;

                foreach (model.optiongroup og in optiongroups)
                {
                    bullettext ui = new bullettext();
                    ui.Bullet = "* ";
                    ui.Text = og.Label;
                    stackpanel_elements.Children.Add(ui);

                    if (og.Children != null && og.Children.Count > 0)
                    {
                        foreach (model.option o in og.Children)
                        {
                            bullettext child = new bullettext();
                            child.Bullet = "- ";
                            child.Text = o.Label;
                            child.DataContext = o;
                            ui.Children.Add(child);
                        }
                    }
                }
            }
            else
            {
                textblock_label.Visibility = Visibility.Collapsed;
                stackpanel_elements.Visibility = Visibility.Collapsed;
            }
        }
    }
}
